package engine.graphics
{
	import away3d.animators.*;
	import away3d.bounds.*;
	import away3d.core.base.*;
	import away3d.core.managers.*;
	import away3d.entities.*;
	import engine.graphics.away3d.*;
	import engine.loaders.*;
	import engine.math.*;
	
	public class RxScene
	{
		private var m_camera:RxCamera3D;
		private var m_models:Vector.<RxLoader3D>;
		private var m_numMeshes:uint;
		private var m_visibleOpaqueMeshes:Vector.<Mesh>;
		private var m_visibleTranslucentMeshes:Vector.<Mesh>;
		private var m_tmpMatrix:RxMatrix4x4;
		
		public function RxScene(camera:RxCamera3D)
		{
			this.m_camera = camera;
			this.m_models = new Vector.<RxLoader3D>;
			this.m_numMeshes = 0;
			this.m_visibleOpaqueMeshes = new Vector.<Mesh>;
			this.m_visibleTranslucentMeshes = new Vector.<Mesh>;
			this.m_tmpMatrix = new RxMatrix4x4();
		}
		
		public function GetNumModels() : uint
		{
			return this.m_models.length;
		}
		
		public function Update(param1:Number) : void
		{
			var _loc_2:int = 0;
			var _loc_3:RxLoader3D = null;
			var _loc_4:Mesh = null;
			var _loc_5:RxMaterial = null;
			var _loc_6:AxisAlignedBoundingBox = null;
			this.m_visibleOpaqueMeshes.length = 0;
			this.m_visibleTranslucentMeshes.length = 0;
			for each (_loc_3 in this.m_models)
			{
				
				this.UpdateModel(_loc_3, param1);
			}
		}
		
		private function UpdateModel(param1:RxLoader3D, param2:Number) : void
		{
			var _loc_3:SmoothSkeletonAnimator = null;
			var _loc_4:RxLoader3D = null;
			var _loc_5:int = 0;
			if (param1.visible && this.UpdateMesh(param1.mesh))
			{
				param1.SetVisible(true);
				_loc_3 = param1.skelAnimator;
				if (_loc_3 != null)
				{
					//_loc_3.Update(param2);
					//param1.mesh.AnimateBBox();
				}
				_loc_5 = 0;
				while (_loc_5 < param1.numChildren)
				{
					
					_loc_4 = param1.getChildAt(_loc_5) as RxLoader3D;
					if (_loc_4 != null)
					{
						this.UpdateModel(_loc_4, param2);
					}
					_loc_5++;
				}
			}
			else
			{
				param1.SetVisible(false);
			}
		}
		
		private function UpdateMesh(param1:Mesh) : Boolean
		{
			/*
			var _loc_3:RxMatrix4x4 = null;
			var _loc_4:AxisAlignedBoundingBox = null;
			var _loc_5:RxMaterial = null;
			var _loc_2:Boolean = false;
			if (param1 != null && param1.visible)
			{
				_loc_3 = param1.sceneTransform;
				_loc_4 = AxisAlignedBoundingBox(param1.bounds);
				if (this.m_camera.IsBoundingBoxInFrustum(_loc_4, _loc_3))
				{
					_loc_2 = true;
					_loc_5 = param1.material as RxMaterial;
					if (_loc_5)
					{
						if (_loc_5.IsBlending())
						{
							this.m_visibleTranslucentMeshes.push(param1);
						}
						else
						{
							this.m_visibleOpaqueMeshes.push(param1);
						}
					}
				}
			}
			return _loc_2;*/
			
			return false;
		}
	}
}